home *** CD-ROM | disk | FTP | other *** search
/ Clickx 96 / Clickx 96.iso / software / tools / tool / xbmc-10.1.exe / addons / script.module.pil / lib / PIL / McIdasImagePlugin.py < prev    next >
Encoding:
Python Source  |  2009-04-06  |  1.7 KB  |  71 lines

  1. #
  2. # The Python Imaging Library.
  3. # $Id$
  4. #
  5. # Basic McIdas support for PIL
  6. #
  7. # History:
  8. # 1997-05-05 fl  Created (8-bit images only)
  9. # 2009-03-08 fl  Added 16/32-bit support.
  10. #
  11. # Thanks to Richard Jones and Craig Swank for specs and samples.
  12. #
  13. # Copyright (c) Secret Labs AB 1997.
  14. # Copyright (c) Fredrik Lundh 1997.
  15. #
  16. # See the README file for information on usage and redistribution.
  17. #
  18.  
  19. __version__ = "0.2"
  20.  
  21. import struct
  22. import Image, ImageFile
  23.  
  24. def _accept(s):
  25.     return s[:8] == "\x00\x00\x00\x00\x00\x00\x00\x04"
  26.  
  27. ##
  28. # Image plugin for McIdas area images.
  29.  
  30. class McIdasImageFile(ImageFile.ImageFile):
  31.  
  32.     format = "MCIDAS"
  33.     format_description = "McIdas area file"
  34.  
  35.     def _open(self):
  36.  
  37.         # parse area file directory
  38.         s = self.fp.read(256)
  39.         if not _accept(s) or len(s) != 256:
  40.             raise SyntaxError("not an McIdas area file")
  41.  
  42.         self.area_descriptor_raw = s
  43.         self.area_descriptor = w = [0] + list(struct.unpack("!64i", s))
  44.  
  45.         # get mode
  46.         if w[11] == 1:
  47.             mode = rawmode = "L"
  48.         elif w[11] == 2:
  49.             # FIXME: add memory map support
  50.             mode = "I"; rawmode = "I;16B"
  51.         elif w[11] == 4:
  52.             # FIXME: add memory map support
  53.             mode = "I"; rawmode = "I;32B"
  54.         else:
  55.             raise SyntaxError("unsupported McIdas format")
  56.  
  57.         self.mode = mode
  58.         self.size = w[10], w[9]
  59.  
  60.         offset = w[34] + w[15]
  61.         stride = w[15] + w[10]*w[11]*w[14]
  62.  
  63.         self.tile = [("raw", (0, 0) + self.size, offset, (rawmode, stride, 1))]
  64.  
  65. # --------------------------------------------------------------------
  66. # registry
  67.  
  68. Image.register_open("MCIDAS", McIdasImageFile, _accept)
  69.  
  70. # no default extension
  71.